home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0027_Dealing with SETS in basm.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  1KB  |  61 lines

  1. {
  2. A set is just an array of bits, each possible element in the set has a bit in
  3. the array. If the element is in the set, the bit is set, otherwise clear.
  4. If you know that (and asm :), you know how to access a set in BASM.
  5.  
  6.  BvG> How would the following routine look in assembler?
  7.  
  8. }
  9.  
  10. type charset=set of char;
  11.  
  12. function epos(str:string; ch:charset; xst:byte):byte;
  13. var i:byte;
  14. begin
  15.   i:=xst;
  16.   while (not (str[i] in ch)) and (i<=length(str)) do inc(i);
  17.   epos:=i;
  18. end;
  19.  
  20. function eposasm(str:string; ch:charset; xst:byte):byte; assembler;
  21. { Same result as pascal version, except for xst=0: }
  22. { this one returns 0, pascal version returns same as xst=1, }
  23. { or 0 if chr(length(Str)) exists in ch }
  24. asm
  25.  cld
  26.  push ds
  27.  lds si,Str
  28.  lodsb
  29.  xor ah,ah
  30.  mov bx,ax
  31.  mov al,xst
  32.  dec ax            { assumes xst>0 }
  33.  add si,ax
  34.  sub bx,ax
  35.  jle @NotFnd       { jump if xst > length(str) }
  36.  les dx,&ch        { ch is a reserved word, so use the identifier operator }
  37. @LoopStr:
  38.  lodsb
  39.  mov di,dx
  40.  mov cl,al
  41.  and cl,7
  42.  shr ax,1
  43.  shr ax,1
  44.  shr ax,1
  45.  mov di,ax
  46.  add di,dx
  47.  mov al,1
  48.  shl al,cl
  49.  test es:[di],al
  50.  jnz @Fnd
  51.  dec bx
  52.  jnz @LoopStr
  53.  jmp @NotFnd
  54. @Fnd:
  55.  dec si                { SI already incremented by lodsb, not wanted }
  56. @NotFnd:
  57.  mov ax,si
  58.  sub ax,word ptr [Str] { The offset of Str }
  59.  pop ds
  60. end;
  61.